#include <gtest/gtest.h>
#include "../mqserver/mq_binding.hpp"
mq_zxws::BindingManager::ptr bmp;
class Binding:public testing::Environment{
public:
    void SetUp() override{
        bmp = std::make_shared<mq_zxws::BindingManager>("./data/meta.db");
    }
    void TearDown() override{
        bmp->clear();
    }
};

// TEST(Binding, insert_test){
//     bmp->Bind("exchange1","queue1", "news.music.#", true);
//     bmp->Bind("exchange1","queue2", "news.sport.#", true);
//     bmp->Bind("exchange1","queue3", "news.gossip.#", true);
//     bmp->Bind("exchange2","queue1", "news.music.pop", true);
//     bmp->Bind("exchange2","queue2", "news.sport.football", true);
//     bmp->Bind("exchange2","queue3", "news.gossip.star", true);
//     ASSERT_EQ(bmp->size(), 6);
// }

// TEST(Binding, select_test){
//     ASSERT_EQ(bmp->exist("exchange1","queue1"), true);
//     ASSERT_EQ(bmp->exist("exchange1","queue2"), true);
//     ASSERT_EQ(bmp->exist("exchange1","queue3"), true);
//     ASSERT_EQ(bmp->exist("exchange2","queue1"), true);
//     ASSERT_EQ(bmp->exist("exchange2","queue2"), true);
//     ASSERT_EQ(bmp->exist("exchange2","queue3"), true);
//     mq_zxws::Binding::ptr bp = bmp->getBinding("exchange1","queue1");
//     ASSERT_EQ(bp->_exchange_name, "exchange1");
//     ASSERT_EQ(bp->_msgqueue_name, "queue1");
//     ASSERT_EQ(bp->_binding_key, "news.music.#");
// }
// TEST(Binding, select_exchange_test){
//     mq_zxws::MsgQueueBindingMap mp = bmp->getExchangeBindings("exchange1");
//     ASSERT_EQ(mp.size(), 3);
//     ASSERT_NE(mp.find("queue1"), mp.end());
//     ASSERT_NE(mp.find("queue2"), mp.end());
// }
// TEST(Binding, remove_queue_test){
//     bmp->removeMsgqueueBindings("queue1");
//     ASSERT_EQ(bmp->exist("exchange1", "queue1"), false);
//     ASSERT_EQ(bmp->exist("exchange2", "queue1"), false);
// }
// TEST(Binding, remove_exchange_test){
//     bmp->removeExchangeBindings("exchange1");
//     ASSERT_EQ(bmp->exist("exchange1", "queue2"), false);
// }

// TEST(Binding, remove_single_test){
//     ASSERT_EQ(bmp->exist("exchange2", "queue2"), true);
//     bmp->unBind("exchange2", "queue2");
//     ASSERT_EQ(bmp->exist("exchange2", "queue2"), false);
//     ASSERT_EQ(bmp->exist("exchange2", "queue3"), true);
// }
TEST(Binding, recovery_test){
    ASSERT_EQ(bmp->exists("exchange2", "queue3"), true);
    ASSERT_EQ(bmp->size(), 1);
}


int main(int argc, char*argv[])
{
    testing::InitGoogleTest(&argc, argv);
    testing::AddGlobalTestEnvironment(new Binding);
    int res = RUN_ALL_TESTS();
    return 0;
}